package cn.hdu.liang.typeinfo.toys;

import java.util.Arrays;

interface HasBatteries {

}

interface Waterproof {

}

interface Shoots {

}

interface Exam2 {

}

class Toy {
    Toy() {

    }

    Toy(int i) {

    }
}

class FancyToy extends Toy implements HasBatteries, Waterproof, Shoots, Exam2 {
    private int x;

    FancyToy() {
        super(1);
    }

}


public class ToyTest {

    static void printInfo(Class cc) {
        System.out.println("Class name: " + cc.getName() + " is 接口吗? [" + cc.isInterface() + "]");
        System.out.println("Simple name: " + cc.getSimpleName());
        System.out.println("Canonical name : " + cc.getCanonicalName());
        System.out.println("DeclaredFields : " + Arrays.toString(cc.getDeclaredFields()));
        System.out.println();
    }

    public static void main(String[] args) {
        Class c = null;
        try {
            c = Class.forName("cn.hdu.liang.typeinfo.toys.FancyToy");
        } catch(ClassNotFoundException e) {
            System.out.println("Can't find FancyToy");
            System.exit(1);
        }
        printInfo(c);

        for(Class face : c.getInterfaces()) {
            printInfo(face);
        }

        Class up = c.getSuperclass();
        Object obj = null;
        try {
            obj = up.newInstance();
        } catch(InstantiationException e) {
            System.out.println("Can't instantiate");
            System.exit(1);
        } catch(IllegalAccessException e) {
            System.out.println("Can't access");
            System.exit(1);
        }
        printInfo(obj.getClass());

    }

}
